package com.huatai.exchange.impl;

import com.faneui.common.exception.BusinessException;
import com.huatai.exchange.dal.dao.ExcCustDataFileDAO;
import com.huatai.exchange.dal.model.ExcCustDataFile;
import com.huatai.exchange.service.ExcCustDataFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExcCustDataFileServiceImpl implements ExcCustDataFileService {

    @Autowired
    private ExcCustDataFileDAO excCustDataFileDAO;

    @Override
    public List<ExcCustDataFile> queryExcCustDataFileList(ExcCustDataFile excCustDataFile) throws BusinessException {
        List<ExcCustDataFile> list = null;
        try{
            list = excCustDataFileDAO.queryByModel(excCustDataFile) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return list;
    }

    @Override
    public ExcCustDataFile queryExcCustDataFile(String id) throws BusinessException {
        ExcCustDataFile dataFile = null;
        try{
            dataFile = excCustDataFileDAO.queryById(id) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return dataFile;
    }

    @Override
    public void modifyCustDataFile(ExcCustDataFile excCustDataFile) throws BusinessException {
        try{
            Long num = excCustDataFileDAO.updateById(excCustDataFile) ;
            if(num == 0) {
                throw new BusinessException("更新失败") ;
            }
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyCustDataFile(String id, String newNextDate, String oldNextDate) throws BusinessException {
        try{
            Long num = excCustDataFileDAO.updateNextDate(id,newNextDate,oldNextDate) ;
            if(num == 0) {
                throw new BusinessException("更新失败") ;
            }
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }
}
